package com.inda.lemurshooter;
import android.content.Context;

import android.graphics.drawable.Drawable;

//A class describing animal types
public class Animal {

	protected int speedX; // Speed in pixels per second
	protected int speedY; // Speed in pixels per second
	protected int timeAlive; // Time alive 
	
	//The size of an animal (all are rectangles)
	 int width;
	 int height;
	
	 //boolean which is true if the animal was just shot
	 boolean exploding;
	 
	//position of animal
	 double x;  double y;
	
	//number of moves taken by animal
	 int moves;
	
	//Image showing the animal type
	 Drawable image;
	
	//Points rewarded if taken this animal
	 int points;
	 
	 // spawn time
	 long spawnTime;
	
	
	//The area in which the animal can spawn
	int rightLimit; int leftLimit; int upLimit; int downLimit;
	
	public Animal()
	{
		spawnTime = System.currentTimeMillis(); // Time born
	}

	public int getWidth() {
		return width;
	}

	public int getHeight() {
		return height;
	}

	public Drawable getImage() {
		return image;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public void setImage(Drawable image) {
		this.image = image;
	}
	
	public void setPoints(int n){
		this.points=n;
	}
	public int getPoints(){
		return points;
	}
	
	//move animal one step 
	// elapsed time * speed = distance
	public void move(long elapsed){
		// Converts elapsed time in ms to seconds and multiplies by set speed.
		x+=(elapsed/(float)1000)*speedX;
		y+=(elapsed/(float)1000)*speedY;
	}
	
	//set the limits for the coordinates in which the animal can move
	public void setLimits(int right, int left, int up, int down){
		rightLimit=right;
		leftLimit=left;
		upLimit=up;
		downLimit=down;
	}
	
	//If the animal has moved enough: return true
	public boolean finished(){
		if(System.currentTimeMillis() - spawnTime >= timeAlive)
			return true;
		
		return false;	
	}

	//Looks if the animal can spawn in the "tried" position in the parameters
	public boolean isPossible(int tryx, int tryy) {
		if(tryx < rightLimit && tryx > leftLimit 
				&& tryy < upLimit && tryy > downLimit)
			return true;
		else
			return false;
	}

	public double getPosX() {
		return x;
	}
	
	public double getPosY() {
		return y;
	}
/**
 * 
 * @param shotX the x coordinate of the tested shot
 * @param shotY the y coordinate of the tested shot
 * @return true if the coordinates is within the animal area
 */
	public boolean isShot(float shotX, float shotY) {
		if(shotX >= x && shotX <= (x+width) &&
				shotY >= y && shotY <= (y+height))
			return true;
		else
			return false;			
	}

	public void shoot() {
		// TODO Auto-generated method stub
		
	}

	public void explode(Drawable explosionImage) {
		exploding =true;
		image=explosionImage;
	}

	public boolean isExploding() {
		return exploding;
	}


}

